﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using SqlCon;

namespace yfxt
{
    public partial class ms_dfcfcx : Form
    {




        //两个窗口传值
        public string s_cfhm_dgw;
        public string S_cfhm_dgw
        {
            get { return this.s_cfhm_dgw; }
            set { this.s_cfhm_dgw = value; }
        }




        SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction);

        public ms_dfcfcx()
        {
            InitializeComponent();
        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            string StrCx = "select cfhm,brxm,fyrq,ksmc,ygxm,(case ms_cf01.cfbz when '0'then '未收费' when '1' then '已收费' end) as cfbz from ms_cf01,gy_ygdm,gy_ksdm where gy_ygdm.ygdm=ms_cf01.ysdm " +
                     "and gy_ksdm.ksdm=ms_cf01.ksdm and fyrq between @fyrq_01 and @fyrq_02";
            //string StrCx = "select cfhm,brxm,fyrq,ksmc,ygxm from V_cf01_ygdm_ksdm";
            if (conn.State != ConnectionState.Open) { conn.Open(); }

            SqlCommand cmd = new SqlCommand(StrCx, conn);

            cmd.Parameters.AddWithValue("@fyrq_01", DateTime.Parse(dateTimePicker1.Text));

            cmd.Parameters.AddWithValue("@fyrq_02", DateTime.Parse(dateTimePicker2.Text));

            SqlDataAdapter da = new SqlDataAdapter();

            da.SelectCommand = cmd;

            DataTable dt = new DataTable();

            da.Fill(dt);

            dataGridView1.DataSource = dt;


            dataGridView1.Columns[0].HeaderCell.Value = "处方号码";
            dataGridView1.Columns[1].HeaderCell.Value = "病人姓名";
            dataGridView1.Columns[2].HeaderCell.Value = "划价日期";
            dataGridView1.Columns[3].HeaderCell.Value = "科室";
            dataGridView1.Columns[4].HeaderCell.Value = "开方医生";
            dataGridView1.Columns[5].HeaderCell.Value = "收费情况";

            label4.Text = dataGridView1.Rows.Count.ToString();
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            string StrCx = "select cfhm,brxm,fyrq,ksmc,ygxm,(case ms_cf01.cfbz when '0'then '未收费' when '1' then '已收费' end) as cfbz from ms_cf01,gy_ygdm,gy_ksdm where gy_ygdm.ygdm=ms_cf01.ysdm " +
                    "and gy_ksdm.ksdm=ms_cf01.ksdm and ms_cf01.cfbz='1' and fyrq between @fyrq_01 and @fyrq_02";
            //string StrCx = "select cfhm,brxm,fyrq,ksmc,ygxm from V_cf01_ygdm_ksdm";
            if (conn.State != ConnectionState.Open) { conn.Open(); }

            SqlCommand cmd = new SqlCommand(StrCx, conn);

            cmd.Parameters.AddWithValue("@fyrq_01", DateTime.Parse(dateTimePicker1.Text));

            cmd.Parameters.AddWithValue("@fyrq_02", DateTime.Parse(dateTimePicker2.Text));

            SqlDataAdapter da = new SqlDataAdapter();

            da.SelectCommand = cmd;

            DataTable dt = new DataTable();

            da.Fill(dt);

            dataGridView1.DataSource = dt;


            dataGridView1.Columns[0].HeaderCell.Value = "处方号码";
            dataGridView1.Columns[1].HeaderCell.Value = "病人姓名";
            dataGridView1.Columns[2].HeaderCell.Value = "划价日期";
            dataGridView1.Columns[3].HeaderCell.Value = "科室";
            dataGridView1.Columns[4].HeaderCell.Value = "开方医生";
            dataGridView1.Columns[5].HeaderCell.Value = "收费情况";

            label4.Text = dataGridView1.Rows.Count.ToString();
        }

        private void radioButton3_CheckedChanged(object sender, EventArgs e)
        {
            string StrCx = "select cfhm,brxm,fyrq,ksmc,ygxm,(case ms_cf01.cfbz when '0'then '未收费' when '1' then '已收费' end) as cfbz from ms_cf01,gy_ygdm,gy_ksdm where gy_ygdm.ygdm=ms_cf01.ysdm " +
                     "and gy_ksdm.ksdm=ms_cf01.ksdm and ms_cf01.cfbz='0' and fyrq between @fyrq_01 and @fyrq_02";
            //string StrCx = "select cfhm,brxm,fyrq,ksmc,ygxm from V_cf01_ygdm_ksdm";
            if (conn.State != ConnectionState.Open) { conn.Open(); }

            SqlCommand cmd = new SqlCommand(StrCx, conn);

            cmd.Parameters.AddWithValue("@fyrq_01", DateTime.Parse(dateTimePicker1.Text));

            cmd.Parameters.AddWithValue("@fyrq_02", DateTime.Parse(dateTimePicker2.Text));

            SqlDataAdapter da = new SqlDataAdapter();

            da.SelectCommand = cmd;

            DataTable dt = new DataTable();

            da.Fill(dt);

            dataGridView1.DataSource = dt;


            dataGridView1.Columns[0].HeaderCell.Value = "处方号码";
            dataGridView1.Columns[1].HeaderCell.Value = "病人姓名";
            dataGridView1.Columns[2].HeaderCell.Value = "划价日期";
            dataGridView1.Columns[3].HeaderCell.Value = "科室";
            dataGridView1.Columns[4].HeaderCell.Value = "开方医生";
            dataGridView1.Columns[5].HeaderCell.Value = "收费情况";

            label4.Text = dataGridView1.Rows.Count.ToString();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            //string StrCx = "select cfhm,brxm,fyrq,ksmc,ygxm,(case ms_cf01.cfbz when '0'then '未收费' when '1' then '已收费' end) as cfbz from ms_cf01,gy_ygdm,gy_ksdm where gy_ygdm.ygdm=ms_cf01.ysdm " +
            //         "and gy_ksdm.ksdm=ms_cf01.ksdm and ms_cf01.cfbz='0' and fyrq between @fyrq_01 and @fyrq_02";
            //    //string StrCx = "select cfhm,brxm,fyrq,ksmc,ygxm from V_cf01_ygdm_ksdm";
            //    if (conn.State != ConnectionState.Open) { conn.Open(); }

            //    SqlCommand cmd = new SqlCommand(StrCx,conn);

            //    cmd.Parameters.AddWithValue("@fyrq_01", DateTime.Parse(dateTimePicker1.Text));

            //    cmd.Parameters.AddWithValue("@fyrq_02", DateTime.Parse(dateTimePicker2.Text));

            //    SqlDataAdapter da = new SqlDataAdapter();

            //    da.SelectCommand = cmd;

            //    DataTable dt = new DataTable();

            //    da.Fill(dt);

            //    dataGridView1.DataSource = dt;


            //    dataGridView1.Columns[0].HeaderCell.Value = "处方号码";
            //    dataGridView1.Columns[1].HeaderCell.Value = "病人姓名";
            //    dataGridView1.Columns[2].HeaderCell.Value = "划价日期";
            //    dataGridView1.Columns[3].HeaderCell.Value = "科室";
            //    dataGridView1.Columns[4].HeaderCell.Value = "开方医生";
            //    dataGridView1.Columns[5].HeaderCell.Value = "收费情况";

            //    label4.Text = dataGridView1.Rows.Count.ToString();

            //    radioButton1.Checked = true;


            if (radioButton1.Checked != true) { radioButton1.Checked = true; }//如果没有选中按钮 设置选中

            this.radioButton1_CheckedChanged(sender, e);//调用radioButton1_CheckedChanged事件进行查询

        }

        private void button2_Click(object sender, EventArgs e)
        {

            if (MessageBox.Show("您是否确定删除这条处方？？", "提示信息", MessageBoxButtons.YesNoCancel) == DialogResult.Yes)
            {
                if (dataGridView1.Rows.Count == 0)
                {
                    MessageBox.Show("当前没有选择想要删除的处方！！");
                    return;
                }

                string StrInsert = "delete from ms_cf01 where cfhm="
                                 + dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["cfhm"].Value.ToString() + " ";
                if (conn.State != ConnectionState.Open) { conn.Open(); }

                SqlCommand cmd = new SqlCommand(StrInsert, conn);

                if (MessageBox.Show("您再一次确定删除这条处方？？", "提示信息", MessageBoxButtons.YesNoCancel) == DialogResult.Yes)
                {
                    cmd.ExecuteNonQuery();
                }
                conn.Close();


            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (dataGridView1.Rows.Count == 0) { return; }
            s_cfhm_dgw = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["cfhm"].Value.ToString();//取得选中的处方号码然后传值给子窗口

            ms_dfcfcx_mx cfcx_mx = new ms_dfcfcx_mx();//将明细窗口设置为本窗口的子窗口

            cfcx_mx.Owner = this;//将明细窗口设置为本窗口的子窗口

            cfcx_mx.ShowDialog();//显示子窗口
        }

        private void button4_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
